package com.ruoyi.order.service.impl;

import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ruoyi.order.mapper.MgOrderAssignMapper;
import com.ruoyi.order.domain.MgOrderAssign;
import com.ruoyi.order.service.IMgOrderAssignService;
import com.basic.service.impl.BaseServiceImpl;
import com.common.util.CopyEntity;
import com.param.concat.IAssignOrderParam;

/**
 * 派稿Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-05-19
 */
@Service
public class MgOrderAssignServiceImpl extends BaseServiceImpl<Long, MgOrderAssign> implements IMgOrderAssignService 
{
    public MgOrderAssignServiceImpl(MgOrderAssignMapper baseMapper) {
		super(baseMapper);
		// TODO Auto-generated constructor stub
	}
    /**
     * 查询派稿
     * 
     * @param id 派稿主键
     * @return 派稿
     */
    @Override
    public MgOrderAssign selectById(Integer id)
    {
        return baseMapper.selectById(id);
    }

    /**
     * 查询派稿列表
     * 
     * @param mgOrderAssign 派稿
     * @return 派稿
     */
    @Override
    public List<MgOrderAssign> selectList(MgOrderAssign mgOrderAssign)
    {
        return baseMapper.selectList(mgOrderAssign);
    }

    /**
     * 新增派稿
     * 
     * @param mgOrderAssign 派稿
     * @return 结果
     */
    @Override
    public int insert(MgOrderAssign mgOrderAssign)
    {
    	insertProperties(mgOrderAssign);
        return baseMapper.insert(mgOrderAssign);
    }

    /**
     * 修改派稿
     * 
     * @param mgOrderAssign 派稿
     * @return 结果
     */
    @Override
    public int update(MgOrderAssign mgOrderAssign)
    {
    	updateProperties(mgOrderAssign);
        return baseMapper.update(mgOrderAssign);
    }

    /**
     * 批量删除派稿
     * 
     * @param ids 需要删除的派稿主键
     * @return 结果
     */
    @Override
    public int deleteByIds(Integer[] ids)
    {
        return baseMapper.deleteByIds(ids);
    }

    /**
     * 删除派稿信息
     * 
     * @param id 派稿主键
     * @return 结果
     */
    @Override
    public int deleteById(Integer id)
    {
        return baseMapper.deleteById(id);
    }
	@Override
	@Transactional(propagation = Propagation.MANDATORY)
	public int selectProcessPersonal(IAssignOrderParam param) {
		
		MgOrderAssign orderAssign = CopyEntity.copyEntity(param, MgOrderAssign.class);
		
		orderAssign.setDispatchTime(System.currentTimeMillis() / 1000);
		return this.insert(orderAssign);
	}
	@Override
	public MgOrderAssign selectByOrderIdAndProcessd(int orderId, int processed) {

		MgOrderAssignMapper orderAssignMapper = this.getBaseMapper();
		return orderAssignMapper.selectByOrderIdAndProcessd(orderId, processed);
	}
	@Override
	public List<MgOrderAssign> getOrderAssigns(long orderId) {
		// TODO Auto-generated method stub
		MgOrderAssignMapper orderAssignMapper = this.getBaseMapper();

		return orderAssignMapper.getOrderAssigns(orderId);
	}
	@Override
	@Transactional(propagation = Propagation.MANDATORY)
	public Integer getOrderAssignsMaxIdForUpdate(long orderId, long processed) {
		
		MgOrderAssignMapper orderAssignMapper = this.getBaseMapper();
	
		return orderAssignMapper.getOrderAssignsMaxIdForUpdate(orderId, processed);
	}
	@Override
	public int complateOrder(int id) {
		
		MgOrderAssign orderAssign = new MgOrderAssign();
		
		orderAssign.setId((long) id);
		
		orderAssign.setOrderStatus(6);
		
		orderAssign.setEditStatus((byte) 2);
		
		return baseMapper.update(orderAssign);
	}
	@Override
	public <P> int updateParam(P parameter) {
	
		MgOrderAssignMapper orderAssignMapper = this.getBaseMapper();
		
		return orderAssignMapper.updateParam(parameter);
	}
}
